import java.io.*;
import java.util.*;
public class Manager 
{
	public static void main(String args []){
		Factory f1=Factory.getFactory(Factory.FR);
		Factory f2=Factory.getFactory(Factory.US);
		ArrayList <Intrare> agenda= new ArrayList <Intrare>();
		String option="";
		do
		{
			System.out.flush();
			System.out.println("A-Add personal information");
			System.out.println("P-Add person");
			System.out.println("T-task");
			System.out.println("S-delete task");
			System.out.println("D-Delete person");
			System.out.println("V-View");
			System.out.println("E-exit");
			BufferedReader tastatura=new BufferedReader(new InputStreamReader(System.in));
		try
		{
		System.out.println("Option:");
		option=tastatura.readLine().toUpperCase();
		if(option.charAt(0)=='A')
		{
		System.out.println("Your name:");
		String name=tastatura.readLine();
		System.out.println("street number");
		Integer streetNr=Integer.parseInt(tastatura.readLine());
		System.out.println("town");
		String town=tastatura.readLine();
		System.out.println("zip code");
		Integer code=Integer.parseInt(tastatura.readLine());
		System.out.println("Phone number");
		String number=tastatura.readLine();
		System.out.println("choose format: 1-FR;2-US");
		Integer op=Integer.parseInt(tastatura.readLine());
		Address a;
		PhoneNumber p;
		if(op==1)
		{
			a=f1.getAddress(streetNr,name,town,code);
		    p=f1.getPhoneNumber(number);
		}
		if (op==2)
		{
			a=f2.getAddress(streetNr,name,town,code);
		    p=f2.getPhoneNumber(number);
		}
		a=f2.getAddress(streetNr,name,town,code);
	    p=f2.getPhoneNumber(number);
	    Intrare e=IntrarePersonala.getInstance(name, a, p);
	    agenda.add(e);
		}
		else
			if(option.charAt(0)=='P')
			{
				System.out.println("Contact name:");
				String name=tastatura.readLine();
				System.out.println("street number");
				Integer streetNr=Integer.parseInt(tastatura.readLine());
				System.out.println("town");
				String town=tastatura.readLine();
				System.out.println("zip code");
				Integer code=Integer.parseInt(tastatura.readLine());
				System.out.println("Phone number");
				String number=tastatura.readLine();
				System.out.println("choose format: 1-FR;2-US");
				Integer op=Integer.parseInt(tastatura.readLine());
				
				Address a;
				PhoneNumber p;
				if(op==1)
				{
					a=f1.getAddress(streetNr,name,town,code);
				    p=f1.getPhoneNumber(number);
				}
				if (op==2)
				{
					a=f2.getAddress(streetNr,name,town,code);
				    p=f2.getPhoneNumber(number);
				}
				a=f2.getAddress(streetNr,name,town,code);
			    p=f2.getPhoneNumber(number);
			    Intrare e=IntrarePersonala.getInstance(name, a, p);
			    agenda.add(e);
				}
			else
				if(option.charAt(0)=='T')
				{
					System.out.println("task name:");
					String name=tastatura.readLine();
					System.out.println("day");
					Integer day=Integer.parseInt(tastatura.readLine());
					System.out.println("month");
					Integer month=Integer.parseInt(tastatura.readLine());
					System.out.println("year");
					Integer year=Integer.parseInt(tastatura.readLine());
					System.out.println("choose format: 1-FR;2-US");
					Integer op=Integer.parseInt(tastatura.readLine());
				    Date d;
					if(op==1)
				    {
				    	d=f1.genDate(month, day , year);
				    }
					if(op==2)
				    {
				    	d=f2.genDate(day, month , year);
				    }
					d=f2.genDate(day, month , year);
					Intrare e=new IntrareTask(name,d);
					agenda.add(e);
				}
				else 
					if (option.charAt(0)=='S')
					{
						System.out.println("Task name");
						String name=tastatura.readLine();
						int index=-1;
						for(int i=0; i<agenda.size(); i++)
						{
							Intrare e=agenda.get(i).copiere();
							if(e.getName().equals(name))
							{
								index=1;
							}
						}
				if (index !=-1)
				{
					agenda.remove(index);
					System.out.println(name+"deleted");
				}
				else
				{
					System.out.println("there is no task by that name");
				}
					}
		
					else
						if(option.charAt(0)=='D')
						{
							System.out.println("Name:");
							String name=tastatura.readLine();
							int index=-1;
							for(int i=0;i<agenda.size(); i++)
							{
								Intrare e=agenda.get(i).copiere();
								if (e.getName().equals(name))
								{
									index=i;
								}
									
							}
				if (index !=-1)
				{
					agenda.remove(index);
					System.out.println("Deleted");
				}
				else
				{
					System.out.println("does not exist");
				}}
				else
		if(option.charAt(0)=='V')
		{
			for(int i=0;i<agenda.size(); i++)
			{
				System.out.println(agenda.get(i).copiere());
			}
		}}
		catch (IOException e)
		{
			e.printStackTrace();
		}
						}				
		while (option.charAt(0) != 'X');
		}}
